<?php

use Silex\Application;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use models\Menu;
use models\Praise;
use utils\out;

/**点赞*/
$app->post('/personal/praise/user/{uid}/type/{type}/sourceId/{sourceId}', function (Application $app, $uid, $type, $sourceId) {
	$praise = Praise::getByUidMid($app['db'], $uid, $type, $sourceId);

	if(!$praise) {
		Menu::incPraise($app['db'], $sourceId);

		Praise::add($app['db'], $uid, $type, $sourceId);
	} else {
		Menu::descPraise($app['db'], $sourceId);

		Praise::remove($app['db'], $uid, $type, $sourceId);
	}
	$result = array('status'=>'ok', "result"=>"ok");
	return $app->json($result);
});

/**是否赞过*/
$app->get('/personal/praise/user/{uid}/type/{type}/sourceId/{sourceId}', function (Application $app, $uid, $type, $sourceId) {
	$praise = Praise::getByUidMid($app['db'], $uid, $type, $sourceId);
	return $app->json(array('status'=>'ok', "result"=>$praise));
});